package com.hfut.jpoa.service.impl;

import java.util.List;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import com.hfut.jpoa.common.dto.ResultDto;
import com.hfut.jpoa.dao.WorkSystemDAO;
import com.hfut.jpoa.dto.WorkSystemDTO;
import com.hfut.jpoa.model.WorkSystem;
import com.hfut.jpoa.service.WorkSystemService;
import com.hfut.jpoa.service.exception.WorkSystemException;

public class WorkSystemServiceImpl implements WorkSystemService
{
	private static final Logger LOGGER = LoggerFactory
	        .getLogger(WorkSystemServiceImpl.class);

	private WorkSystemDAO workSystemDAO;

	public ResultDto<WorkSystem> queryInfoForPage(WorkSystemDTO condition)
	        throws WorkSystemException
	{
		ResultDto<WorkSystem> findInfoForPage = workSystemDAO
		        .findInfoForPage(condition);
		return findInfoForPage;
	}

	public void update(WorkSystem record) throws WorkSystemException
	{
		if (null == record)
		{
			LOGGER.error("修改工作制度异常");
			throw new WorkSystemException("修改工作制度异常");
		}
		workSystemDAO.updateByPrimaryKeySelective(record);
	}

	public WorkSystem findInfo(WorkSystem condition) throws WorkSystemException
	{
		if (null == condition)
		{
			LOGGER.error("查询工作制度详情异常");
			throw new WorkSystemException("查询工作制度详情异常");
		}
		return workSystemDAO.selectByPrimaryKey(condition.getId());
	}

	public boolean codeValidator(WorkSystem condition)
	        throws WorkSystemException
	{
		// TODO Auto-generated method stub
		return false;
	}

	public List<WorkSystem> queryList(WorkSystem condition)
	        throws WorkSystemException
	{
		// TODO Auto-generated method stub
		return null;
	}

	public void saveWorkSystem(WorkSystem workSystem)
	        throws WorkSystemException
	{
		if (null == workSystem)
		{
			LOGGER.error("workSystem is empty.");
			throw new WorkSystemException("workSystem info is empty");
		}

		workSystemDAO.insert(workSystem);

	}

	public WorkSystemDAO getWorkSystemDAO()
	{
		return workSystemDAO;
	}

	public void setWorkSystemDAO(WorkSystemDAO workSystemDAO)
	{
		this.workSystemDAO = workSystemDAO;
	}

	public int delete(WorkSystem workSystem) throws WorkSystemException
	{
		if (null == workSystem)
		{
			LOGGER.error("workSystem is empty.");
			throw new WorkSystemException("workSystem info is empty");
		}
		return workSystemDAO.deleteByPrimaryKey(workSystem.getId());

	}

}
